# mysite/asgi.py
import os
import django

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "aichat.settings")
django.setup()

from channels.http import AsgiHandler

django_asgi_app = AsgiHandler()

from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from chat.routing import websocket_urlpatterns

application = ProtocolTypeRouter({
    "http": django_asgi_app,
    "websocket": AuthMiddlewareStack(URLRouter(websocket_urlpatterns)),
})
